﻿@using Coralcode.Base.Entity
@{
    Layout = null;
}
<div class="">
    <div class="tablelist_style1" data-js="tabellist_style1">
        <div class="funsearch p_1 pl_2 pr_2">
            <a class="btn_5 f_r ml_3 j_ajax_load" href="/m/node/createNodeByMenu?menuId=@ViewBag.Menu.Id">添加内容</a>
            <div class="f_r">
                <form method="POST" action="/m/node/listNode">
                    <span class="t_des f_l pt_0-5">内容名称：</span>
                    <label class="search f_l">
                        <input type="text" class="text" name="k" />
                        @Html.AntiForgeryToken()
                        <input type="submit" value="" class="submit" /></label>
                </form>
            </div>
        </div>
        <table cellpadding="0" cellspacing="0" class="mt_3-5">
            <tr class="exclude">
                <th width="60">选择</th>
                <th width="100" align="left">ID</th>
                <th align="left">标题</th>
                <th>创建时间</th>
                <th width="60">状态</th>
                <th width="140">操作</th>
            </tr>
            @helper ShowTime(DateTime time)
            {
                DateTime now = DateTime.Now;
                if (now.Year - time.Year == 0)
                {
                    @time.ToString("MM-dd HH:mm");
                }
                else
                {
                    @time.ToString("yyyy-MM-dd HH:mm");
                }
                            
            }
            @foreach (var item in Model.Items)
            {
                <tr>
                    <td>
                        <label class="checkbox_own">
                            <input type="checkbox" value="@item.Id"/></label></td>
                    <td class="td_left">@item.Id</td>
                    <td class="td_left"><a class="j_ajax_load" href="/m/node/editNodeByMenu/@item.Id?categoryId=@item.CategoryId&menuId=@ViewBag.Menu.Id">@item.Title</a>
                    </td>
                    <td>@ShowTime(item.CreateTime)</td>
                    @*<td><a href="#" class="ico ico_moveup mr_2 f_no  btn"></a><a href="#" class="ico ico_movedown btn"></a>
                                 </td>*@
                    <td><a href="/m/node/ChangeNodeStatus/@item.Id" class="ico ico_eye_@item.Status js_changestate btn"></a></td>
                    <td>
                        <div class="fun">
                            <a class="j_ajax_load" href="/m/node/editNodeByMenu/@item.Id?categoryId=@item.CategoryId&menuId=@ViewBag.Menu.Id">编辑</a><a href="/m/node/deleteNode/@item.Id" class="js_delete">删除</a><a href="/m/node/ListRelNode?nodeId=@item.Id" rel="#overlay">关联</a>
                        </div>
                    </td>
                </tr>
            }
        </table>
        <div class="global_fun ">
            <label class="checkbox_own gloabal_select">
                <input type="checkbox" /></label>
            <input type="button" class="btn_4 btn invert" value="反选" /><input type="button" class="btn_4 btn reset"
                                                                              value="重置" />
            <a href="/m/node/DelBatchNode" class="js_delete">删除</a>
        </div>
    </div>
</div>


<script>
    $("a[rel]").overlay({
        mask: {
            color: '#000',
            opacity: 0.6
        },
        closeOnClick: false,
        fixed: false,
        left: 'center',
        top: 'center',
        onBeforeLoad: function () {
            $('.js-overlay-node').load(this.getTrigger().attr("href"));
        }
    });

    $('.js-overlay_close').live("click", function () {
        $('.close').trigger("click");
    });
    var js = $('[data-js]');
    //tablelist_style1 选中切换
    js.filter("[data-js='tabellist_style1']").find("td .checkbox_own").click(function (e) {
        var $this = $(this);
        if ($this.hasClass("selected")) {
            $this.parents("tr").removeClass("selected");
        }
        else {
            $this.parents("tr").addClass("selected");
        }
    }).end().find(".global_fun .gloabal_select").click(function (e) {
        var $this = $(this);
        if ($this.hasClass("selected")) {
            $(this).parents("[data-js='tabellist_style1']").find("td .checkbox_own").each(function () {
                if ($(this).hasClass("selected")) {
                    $(this).trigger("click");
                }
            })
        }
        else {
            $(this).parents("[data-js='tabellist_style1']").find("td .checkbox_own").each(function () {
                if (!$(this).hasClass("selected")) {
                    $(this).trigger("click");
                }
            })
        }
    }).siblings(".invert").click(function () {
        var $checkbox = $(this).siblings(".checkbox_own");
        if ($checkbox.hasClass("selected")) {
            $checkbox.trigger("click.own");
        }
        $(this).parents("[data-js='tabellist_style1']").find("td .checkbox_own").each(function () {
            $(this).trigger("click");
        })
    }).siblings(".reset").click(function () {
        var $checkbox = $(this).siblings(".checkbox_own");
        if ($checkbox.hasClass("selected")) {
            $checkbox.trigger("click.own");
        }
        $(this).parents("[data-js='tabellist_style1']").find("td .checkbox_own").each(function () {
            if ($(this).hasClass("selected")) {
                $(this).trigger("click");
            }
        })
    });
    $(".global_fun").find(".js_delete").click(function (e) {//删除多条内容
        e.preventDefault();
        var href = $(this).attr("href");
        var $elements = $(this).parents("[data-js='tabellist_style1']").find("td .checkbox_own input[type='checkbox']:checked");
        if ($elements.length == 0) {
            alert("请至少选择一条要操作的对象！");
        } else {
            $.confirm("确定操作这些内容吗？", function () {
                var ids = new Array();
                $elements.each(function () {
                    ids.push($(this).val());
                });
                $.post(href, { ids: ids.join(',') }, function (msg) {
                    if (msg.Type == 5) {
                        $.dialog({
                            content: '<div class="success">' + msg.Msg + '</div>',
                            time: 1000,
                            lock: true
                        });
                        $elements.each(function(i,n) {
                            $(n).parents('tr').remove();
                        });
                    }
                    else {
                        $.dialog({
                            content: '<div class="fail">' + msg.Msg + '</div>',
                            time: 1000,
                            lock: true
                        });
                    }
                });
            })
        }
    })
    $("td .fun .js_delete").click(function (e) { //删除内容
        e.preventDefault();
        var $this = $(this);
        var href = $this.attr("href");
        $.confirm("您确定要此操作码？", function () {
            $.post(href, function (msg) {
                if (msg.Type == 5) {
                    $.dialog({
                        content: '<div class="success">' + msg.Msg + '</div>',
                        time: 1000,
                        lock: true
                    });
                    $this.parents('tr').remove();
                } else {
                    $.dialog({
                        content: '<div class="fail">' + msg.Msg + '</div>',
                        time: 1000,
                        lock: true
                    });
                }
            });
        });
    });
</script>